using System.Collections.ObjectModel;
using System.IO;
using System.Xml;

namespace DbBuilder
{
	public class ScriptList : Collection<ScriptStep>
	{
		public ScriptList(XmlNodeList stepNodes)
		{
			load(stepNodes);
		}

		private void load(XmlNodeList stepNodes)
		{
			foreach (XmlNode stepNode in stepNodes)
			{
				Add(new ScriptStep(stepNode));
			}
		}

		public ScriptList(string fileName)
		{
			XmlDocument xml = new XmlDocument();
			xml.Load(Path.Combine(Program.Instance.config_root_folder, fileName));
			load(xml.SelectNodes("Steps/Step"));
		}

		public bool Execute(bool redeployableOnly)
		{
			foreach (ScriptStep step in this)
			{
				if (!step.Execute(redeployableOnly))
				{
					return false;
				}
			}
			return true;
		}
	}
}